import Vue from 'vue';
import Main from './main.vue';

let MessageConstructor = Vue.extend(Main);

let instance;

const previewImg = function(data) {

  // 必须传
  if(!data || !data.list && !data.list.length){
      throw new Error('必须传list');
  }

  if(!instance){
    instance = new MessageConstructor();
    instance.vm = instance.$mount();
  }

  document.body.appendChild(instance.vm.$el);

  // 添加数组
  if(data){
    instance.vm.imgList = data.list?data.list:[]
    instance.vm.index = data.index?data.index:0
    instance.vm.options = data.options?data.options:{}
  }

  // 显示
  instance.vm.show = true;
  
  // 获取don节点
  instance.dom = instance.vm.$el;


  
  return instance.vm;
};

export default previewImg;
